package com.ruoyi.web.controller.task;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.task.domain.ChannelConfig;
import com.ruoyi.task.service.IChannelConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 通道配置Controller
 * 
 * @author ruoyi
 * @date 2025-06-19
 */
@RestController
@RequestMapping("/channel/config")
public class ChannelConfigController extends BaseController
{
    @Autowired
    private IChannelConfigService channelConfigService;

    /**
     * 查询通道配置列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChannelConfig channelConfig)
    {
        startPage();
        List<ChannelConfig> list = channelConfigService.selectChannelConfigList(channelConfig);
        return getDataTable(list);
    }

    /**
     * 导出通道配置列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:config:export')")
    @Log(title = "通道配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChannelConfig channelConfig)
    {
        List<ChannelConfig> list = channelConfigService.selectChannelConfigList(channelConfig);
        ExcelUtil<ChannelConfig> util = new ExcelUtil<ChannelConfig>(ChannelConfig.class);
        util.exportExcel(response, list, "通道配置数据");
    }

    /**
     * 获取通道配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:config:query')")
    @GetMapping(value = "/{channelId}")
    public AjaxResult getInfo(@PathVariable("channelId") Long channelId)
    {
        return success(channelConfigService.selectChannelConfigByChannelId(channelId));
    }

    /**
     * 新增通道配置
     */
    @PreAuthorize("@ss.hasPermi('equipment:config:add')")
    @Log(title = "通道配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChannelConfig channelConfig)
    {
        channelConfig.setCreateBy(getUsername());
        channelConfig.setUpdateBy(getUsername());
        return toAjax(channelConfigService.insertChannelConfig(channelConfig));
    }

    /**
     * 修改通道配置
     */
    @PreAuthorize("@ss.hasPermi('equipment:config:edit')")
    @Log(title = "通道配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChannelConfig channelConfig)
    {
        channelConfig.setUpdateBy(getUsername());
        return toAjax(channelConfigService.updateChannelConfig(channelConfig));
    }

    /**
     * 删除通道配置
     */
    @PreAuthorize("@ss.hasPermi('equipment:config:remove')")
    @Log(title = "通道配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{channelIds}")
    public AjaxResult remove(@PathVariable Long[] channelIds)
    {
        return toAjax(channelConfigService.deleteChannelConfigByChannelIds(channelIds));
    }
}
